Skip to content

feat(payments): add Pay for Data (Heurist) use case#1465

Open
joshuamarksmith wants to merge 13 commits into
awslabs:mainfrom
joshuamarksmith:feat/pay-for-data-heurist
Open

feat(payments): add Pay for Data (Heurist) use case#1465
joshuamarksmith wants to merge 13 commits into
awslabs:mainfrom
joshuamarksmith:feat/pay-for-data-heurist

Conversation

@joshuamarksmith
Copy link
Copy Markdown

A Strands-based finance research agent that calls paid Heurist x402 endpoints for real-time prices, SEC filings, and macro indicators. The AgentCorePaymentsPlugin intercepts HTTP 402 responses, asks the AgentCore payment manager to generate a payment proof against the configured payment instrument and payment session, and retries automatically — tool code stays an ordinary http_request call. Data is analyzed in AgentCore Code Interpreter and exported as charts and reports.

Highlights:

  • HTTP 402 payment processing via AgentCorePaymentsPlugin — no manual payment code in tools
  • Embedded wallet (Coinbase CDP) with USDC as the settlement asset
  • AgentCore Code Interpreter for pandas/matplotlib analysis and artifact export
  • Public PyPI dependencies only (bedrock-agentcore==1.9.0) — no bundled or file-based SDK components
  • Targets x402 on Base mainnet (Heurist endpoints settle on Base)

Adds:

  • 01-tutorials/13-AgentCore-payments/02-use-cases/pay-for-data/
    • pay-for-data.ipynb (notebook walkthrough)
    • heurist_finance_agent/ (agent, catalog, config, artifact_export)
    • scripts/ (sync_registry, run CLI entry points)
    • requirements.txt, .env.example, README.md, .gitignore

Updates:

  • 01-tutorials/13-AgentCore-payments/README.md: add Use Cases table entry
  • 01-tutorials/13-AgentCore-payments/02-use-cases/README.md: add use case overview and highlights

A Strands-based finance research agent that calls paid Heurist x402 endpoints
for real-time prices, SEC filings, and macro indicators. The
AgentCorePaymentsPlugin intercepts HTTP 402 responses, asks the AgentCore
payment manager to generate a payment proof against the configured payment
instrument and payment session, and retries automatically — tool code stays
an ordinary http_request call. Data is analyzed in AgentCore Code Interpreter
and exported as charts and reports.

Highlights:
- HTTP 402 payment processing via AgentCorePaymentsPlugin — no manual
  payment code in tools
- Embedded wallet (Coinbase CDP) with USDC as the settlement asset
- AgentCore Code Interpreter for pandas/matplotlib analysis and artifact
  export
- Public PyPI dependencies only (bedrock-agentcore==1.9.0) — no bundled or
  file-based SDK components
- Targets x402 on Base mainnet (Heurist endpoints settle on Base)

Adds:
- 01-tutorials/13-AgentCore-payments/02-use-cases/pay-for-data/
  - pay-for-data.ipynb (notebook walkthrough)
  - heurist_finance_agent/ (agent, catalog, config, artifact_export)
  - scripts/ (sync_registry, run CLI entry points)
  - requirements.txt, .env.example, README.md, .gitignore

Updates:
- 01-tutorials/13-AgentCore-payments/README.md: add Use Cases table entry
- 01-tutorials/13-AgentCore-payments/02-use-cases/README.md: add use case
  overview and highlights
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions Bot added the 01-tutorials 01-tutorials label May 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Latest scan for commit: 01355a6 | Updated: 2026-05-15 21:02:00 UTC

Security Scan Results

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-05-15T21:01:45+00:00
  • ASH version: 3.0.0

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

Column Explanations:

Severity Levels (S/C/H/M/L/I):

  • Suppressed (S): Security findings that have been explicitly suppressed/ignored and don't affect the scanner's pass/fail status
  • Critical (C): The most severe security vulnerabilities requiring immediate remediation (e.g., SQL injection, remote code execution)
  • High (H): Serious security vulnerabilities that should be addressed promptly (e.g., authentication bypasses, privilege escalation)
  • Medium (M): Moderate security risks that should be addressed in normal development cycles (e.g., weak encryption, input validation issues)
  • Low (L): Minor security concerns with limited impact (e.g., information disclosure, weak recommendations)
  • Info (I): Informational findings for awareness with minimal security risk (e.g., code quality suggestions, best practice recommendations)

Other Columns:

  • Time: Duration taken by each scanner to complete its analysis
  • Action: Total number of actionable findings at or above the configured severity threshold that require attention

Scanner Results:

  • PASSED: Scanner found no security issues at or above the configured severity threshold - code is clean for this scanner
  • FAILED: Scanner found security vulnerabilities at or above the threshold that require attention and remediation
  • MISSING: Scanner could not run because required dependencies/tools are not installed or available
  • SKIPPED: Scanner was intentionally disabled or excluded from this scan
  • ERROR: Scanner encountered an execution error and could not complete successfully

Severity Thresholds (Thresh Column):

  • CRITICAL: Only Critical severity findings cause scanner to fail
  • HIGH: High and Critical severity findings cause scanner to fail
  • MEDIUM (MED): Medium, High, and Critical severity findings cause scanner to fail
  • LOW: Low, Medium, High, and Critical severity findings cause scanner to fail
  • ALL: Any finding of any severity level causes scanner to fail

Threshold Source: Values in parentheses indicate where the threshold is configured:

  • (g) = global: Set in the global_settings section of ASH configuration
  • (c) = config: Set in the individual scanner configuration section
  • (s) = scanner: Default threshold built into the scanner itself

Statistics calculation:

  • All statistics are calculated from the final aggregated SARIF report
  • Suppressed findings are counted separately and do not contribute to actionable findings
  • Scanner status is determined by comparing actionable findings to the threshold
Scanner S C H M L I Time Action Result Thresh
bandit 0 0 0 0 0 0 927ms 0 PASSED MED (g)
cdk-nag 0 0 0 0 0 0 29.3s 0 PASSED MED (g)
cfn-nag 0 0 0 0 0 0 36ms 0 PASSED MED (g)
checkov 0 0 0 0 0 0 5.5s 0 PASSED MED (g)
detect-secrets 0 0 0 0 0 0 883ms 0 PASSED MED (g)
grype 0 0 0 0 0 0 40.7s 0 PASSED MED (g)
npm-audit 0 0 0 0 0 0 182ms 0 PASSED MED (g)
opengrep 0 0 0 0 0 0 <1ms 0 SKIPPED MED (g)
semgrep 0 0 0 0 0 0 <1ms 0 MISSING MED (g)
syft 0 0 0 0 0 0 2.2s 0 PASSED MED (g)

Joshua Smith added 4 commits May 9, 2026 14:57
1. Fix requirements.txt: bedrock-agentcore[strands-agents]==1.9.0 (extras
   install required for AgentCorePaymentsPlugin)
2. Change default prompt to non-crypto macroeconomic query (FredMacroAgent
   GDP/unemployment summary) in run.py and README
3. Remove 'no bundled/file-based SDK' line from README, 02-use-cases/README,
   and tutorial-level README table entry
4. Expand notebook: add architecture diagram (ASCII), AgentCore payments
   capabilities table (payment manager, instrument, session, processing,
   limits), step-by-step payment flow explanation, and restructure into
   numbered steps
5. Add cleanup section (local cache + artifacts) and shared responsibility
   model table to notebook
Comment thread 01-tutorials/13-AgentCore-payments/02-use-cases/pay-for-data/requirements.txt Outdated
- agent.py: remove redundant 'No manual payment logic is needed' from docstring
- artifact_export.py: replace multi-strategy JSON fallback parser with a
  single json.loads — the Code Interpreter runs our own script that always
  emits print(json.dumps(payload)), so the output is deterministic JSON
- catalog.py: warn (via logging.warning) when a requested agent ID is not
  found in the live catalog, so renames or removals surface immediately
  rather than silently loading zero tools
- requirements.txt: pin strands-agents==1.36.0, strands-agents-tools==0.5.0,
  boto3==1.43.1, botocore==1.43.3 to match PR awslabs#1459 versions; keep
  bedrock-agentcore[strands-agents]==1.9.0 (newer than awslabs#1459)
- catalog.py line 199 (f-string suggestion): left as-is — the lines.append
  + join pattern is idiomatic for multi-line table construction and already
  uses f-strings inside the loop
@mvangara10
Copy link
Copy Markdown
Contributor

Please update the use case to use AgentCore runtime and AgentCore observability

Copy link
Copy Markdown

@leewc leewc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM from my side. You might want to address Madhu's comments

Joshua Smith added 4 commits May 13, 2026 20:33
Deploy the Heurist finance agent to AgentCore Runtime with full feature
parity: AgentCore Code Interpreter, S3 artifact storage, and automatic
observability via CloudWatch GenAI Observability.

## What's new

### runtime_agent.py (new)
AgentCore Runtime entry point using BedrockAgentCoreApp. Key design:

- Stateless, payload-driven: all payment config (manager ARN, session ID,
  instrument ID) comes from the invocation payload. The container holds no
  credentials. The app backend (ManagementRole) creates payment sessions with
  spending limits; the execution role (ProcessPaymentRole) can only spend
  within those limits.

- AgentCore Code Interpreter: AgentCoreCodeInterpreter is a remote AWS API
  and works identically from a Runtime container. pandas/matplotlib analysis
  and chart generation are fully supported.

- S3 artifact storage: two @tool functions replace local disk writes —
  export_artifact_to_s3 (binary files from CI sandbox) and save_report_to_s3
  (text/CSV/markdown). Both upload to S3 and return presigned URLs in the
  invocation response:
    {"response": "...", "artifacts": [{"name": "chart.png", "url": "...", "expires_in": 3600}]}
  If CI_ARTIFACTS_BUCKET is not set the agent degrades gracefully: charts
  become markdown tables, text returns inline.

- Thread-local state (threading.local) for per-invocation CI session name
  and artifact list — correct for concurrent Runtime requests.

- Observability: agentcore deploy configures the container to run under
  opentelemetry-instrument, automatically emitting OTel traces and logs to
  CloudWatch GenAI Observability. No instrumentation code required.

### pay-for-data.ipynb (rewritten)
Runtime-only, 8-step notebook:
  1. Configure credentials
  2. Sync Heurist catalog (bundled in container image at build time)
  3. Create private S3 artifacts bucket
  4. Install agentcore CLI, scaffold project, copy files, deploy
  5. Add IAM permissions to execution role (payment + CI + S3)
  6. Invoke deployed agent, inspect response + session spend
  7. View CloudWatch GenAI Observability dashboard
  8. Cleanup (Runtime stack + S3 bucket)

### README.md (rewritten)
Runtime-only documentation:
- Architecture diagram reflects the deployed topology
- Quick Start maps to the 8-step notebook
- Runtime agent section covers: stateless design, Code Interpreter, S3
  artifact response shape, graceful degradation, IAM permissions table
- Prerequisites updated (Node.js 20+, Docker, CDK)

## IAM permissions added to execution role

  PaymentDataPlaneAccess:
    bedrock-agentcore: ProcessPayment, GetPaymentInstrument,
      GetPaymentInstrumentBalance, GetPaymentSession, GetResourcePaymentToken
    Resource: payment-manager/*

  CodeInterpreterAccess:
    bedrock-agentcore: StartCodeInterpreterSession,
      StopCodeInterpreterSession, InvokeCodeInterpreter
    Resource: code-interpreter/*

  S3ArtifactsAccess:
    s3: PutObject, GetObject
    Resource: <bucket>/heurist-finance-artifacts/*

The execution role does not receive CreateSession, CreateInstrument, or
any control-plane payment permissions.
Add aws-opentelemetry-distro>=0.10.0 to the Runtime container's pyproject.toml.
This enables botocore auto-instrumentation which injects W3C traceparent headers
into outgoing boto3 calls, stitching Code Interpreter and payment spans as child
spans in the unified Runtime trace.

AgentCore Observability docs explicitly list StartCodeInterpreterSession,
InvokeCodeInterpreter, and StopCodeInterpreterSession as supporting traceparent
for cross-service trace correlation:
https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability-configure.html

Update Step 7 observability description to accurately reflect what is now stitched:
- Strands agent spans (LLM calls, tool calls, agent turns)
- Code Interpreter calls as child spans via traceparent propagation
- Payment boto3 calls as child spans via botocore instrumentation

Update README Runtime Deployment section accordingly.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the python query

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the tutorail dependency

@rajuans
Copy link
Copy Markdown

rajuans commented May 15, 2026

agent.py is undocumented — unclear when/why to use it

The README's Layout section omits agent.py entirely, and the Quick Start says "Open pay-for-data.ipynb" which only deploys runtime_agent.py. A user cloning this sample has no indication of when or why they would use agent.py.

Additionally, agent.py duplicates significant logic from runtime_agent.py (system prompt, payments plugin config, tool wiring, agent creation) — any future change must be made in two places.

Suggestion: Either:

  1. Add agent.py to the Layout section with a clear explanation (e.g., "local development CLI — run directly without deploying to AgentCore Runtime"), or
  2. Remove it if the notebook is the only supported entry point.

| | |
|---|---|
| AgentCore components | AgentCore payments, AgentCore Code Interpreter, AgentCore Runtime |
| Agent framework | [Strands Agents](https://strandsagents.com/) |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strands is Agent SDK. Its not framework.

Comment on lines +31 to +55
## How It Works

`AgentCorePaymentsPlugin` handles the entire x402 payment lifecycle:

```python
from bedrock_agentcore.payments.integrations.strands import (
AgentCorePaymentsPlugin,
AgentCorePaymentsPluginConfig,
)

payment_plugin = AgentCorePaymentsPlugin(
config=AgentCorePaymentsPluginConfig(
payment_manager_arn=PAYMENT_MANAGER_ARN,
user_id=USER_ID,
payment_instrument_id=PAYMENT_INSTRUMENT_ID,
payment_session_id=PAYMENT_SESSION_ID,
region="us-west-2",
)
)

agent = Agent(
model=BedrockModel(model_id=MODEL_ID),
tools=[http_request, code_interpreter, export_artifact_to_s3, ...],
plugins=[payment_plugin],
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to provide the code sample in readme? Can we add flow in How it work section?

@@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""Fetch the live Heurist catalog and refresh the local cache.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add how agent would be using this file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

01-tutorials 01-tutorials

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants